﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LIB
{
    public class JsWrite
    {

        #region alert and confirm
        /// <summary>
        /// 弹出提示框
        /// </summary>
        /// <param name="page">当前页面this</param>
        /// <param name="msg">提示消息</param>
        public static void Alert(System.Web.UI.Page page, string msg)
        {
            page.Response.Write("<script>alert('" + msg + "');</script>");
        }

        public static void AlertAndGoback(System.Web.UI.Page page, string msg)
        {
            page.Response.Write("<script>alert('" + msg + "');history.go(-1);</script>");
            page.Response.End();
        }

        public static void alertAndClose(System.Web.UI.Page page, string msg)
        {
            page.Response.Write("<script>alert('" + msg + "');window.opener=null;window.close();</script>");
            page.Response.End();
        }

        /// <summary>
        /// 弹出提示框，点确定后跳转
        /// </summary>
        /// <param name="page">当前页面this</param>
        /// <param name="msg">提示消息</param>
        /// <param name="gotourl">跳转页面</param>
        public static void AlertAndGo(System.Web.UI.Page page, string msg, string gotourl)
        {
            page.Response.Write("<script>alert('" + msg + "');location.href='" + gotourl + "';</script>");
            page.Response.End();
        }

        /// <summary>
        /// 确认对话框
        /// </summary>
        /// <param name="page">当前页面this</param>
        /// <param name="msg">提示消息</param>
        /// <param name="yesUrl">点确认后跳转的页面，为空则不做任何跳转</param>
        /// <param name="noUrl">点取消后跳转的页面，为空则不做任何跳转</param>
        public static void Confirm(System.Web.UI.Page page, string msg, string yesUrl, string noUrl)
        {
            if (noUrl == "")
            {
                if (yesUrl == "")
                    page.Response.Write("<script>confirm('" + msg + "');</script>");
                else
                    page.Response.Write("<script>if(confirm('" + msg + "'))location.href='" + yesUrl + "';</script>");
            }
            else
            {
                if (yesUrl == "")
                    page.Response.Write("<script>if(!confirm('" + msg + "'))location.href='" + noUrl + "';</script>");
                else
                    page.Response.Write("<script>if(confirm('" + msg + "'))location.href='" + yesUrl + "';else location.href='" + noUrl + "';</script>");
            }
        }


        #endregion

    }
}
